fn main() {
    test_if();
    println!("-------------------------");
    test_loop();
    println!("-------------------------");
    test_while();
    println!("-------------------------");
    test_for();
}
fn test_if() {
    let num = 3;
    //if num {//err
    if num < 5 {
        println!("Condition was < 5");
    } else if num < 10 {
        println!("Condition was [5,10)");
    } else {
        println!("Condition was >= 10");
    }

    let con = true;
    let num = if con { 5 } else { 10 };
    //let num = if con { 5 } else { "a" };//err
    println!("The value of num is: {num}");
}
fn test_loop() {
    let mut i = 0;
    loop {
        println!("again!");
        i += 1;
        if i >= 10 {
            break;
        }
    }

    i = 0;
    let result = loop {
        i += 1;
        if i >= 10 {
            break i * 2;
        }
    };
    println!("The value of result is: {result}");

    i = 0;
    'counting_up: loop {
        println!("count == {i}");
        let mut remaining = 10;
        loop {
            println!("remaining = {remaining}");
            if remaining == 9 {
                break;
            }
            if i == 2 {
                break 'counting_up;
            }
            remaining -= 1;
        }
        i += 1;
    }
    println!("End count = {i}");
}

fn test_while() {
    let mut num = 3;
    while num >= 0 {
        println!("num is {num}");
        num -= 1;
    }
    println!("LIFTOFF!!!");
}

fn test_for() {
    let arr = [10, 20, 30, 40, 50];

    let mut i = 0;
    for elem in arr {
        println!("elem{i} is : {elem}");
        i += 1;
    }

    for number in (1..4).rev() {
        println!("{number}!");
    }
    println!("LIFTOFF!!!");
}
